# swivel.py

from __future__ import division

from ot_simulator.component import component

class swivel(component.component):
    '''This rotates the coordinate system on a specified axis.

    ===============  ==========================
     Input setting   
    ===============  ==========================
    axis             'X', 'Y' or 'Z'
    angle            degrees
    ===============  ==========================

    ===============  ==========================
    Output setting
    ===============  ==========================
    <none>
    ===============  ==========================
    '''
    input_parameters = ('axis', 'angle')

    def get_transform(self, params, transform_in):
        axis_param = self.get_param(params, 'axis')
        axis = axis_param.upper()
        angle = self.get_param(params, 'angle')
        if axis == 'X': return transform_in.rotate_x(angle)
        if axis == 'Y': return transform_in.rotate_y(angle)
        if axis == 'Z': return transform_in.rotate_z(angle)
        raise ValueError("%s illegal 'axis' parameter: %r" %
                           (self.name, axis_param))


def test():
    import doctest
    import sys
    sys.exit(doctest.testmod()[0])

if __name__ == "__main__":
    test()
